const backgroundAudioManager = wx.getBackgroundAudioManager();
const componentObj = {
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        size: 'mini',
        running: false
    },

    /**
     * 组件的方法列表
     */
    methods: {
        play() {
            if (!backgroundAudioManager.paused) { // 如果播放着  就停止
                wx.showToast({
                    title: '正在播放中...',
                    icon:'none'
                })
                return 
            } 
            if(!backgroundAudioManager.src){
                backgroundAudioManager.src = 'http://47.94.230.236/statics/home/img/dayu.mp3'
                return
            }
            backgroundAudioManager.play()
        },
        pause() {
            backgroundAudioManager.pause()
        },
        stop() {
            backgroundAudioManager.stop()
        }
    },
    attached: function () {
        if (!backgroundAudioManager.paused) { // 如果播放着  就停止
            backgroundAudioManager.stop()
        }
        backgroundAudioManager.title = '大禹治水'
        backgroundAudioManager.epname = '讲故事'
        backgroundAudioManager.singer = '小薇'
        backgroundAudioManager.coverImgUrl = 'http://203.195.220.169:6892/img.jpg'
        backgroundAudioManager.src = 'http://47.94.230.236/statics/home/img/dayu.mp3'
        let self = this;
        backgroundAudioManager.onPlay(() => {
            self.setData({
                running: true
            })
        })
        backgroundAudioManager.onStop(() => {
            self.setData({
                running: false
            })
        })
        backgroundAudioManager.onPause(() => {
            self.setData({
                running: 'pause'
            })
        })
        backgroundAudioManager.onError((err) => {
            console.log(err)
        })
    }
}

Component(componentObj)